c###lngpat.for
      SUBROUTINE LNGPAT
C--------------------------------
C
C     THIS SUBROUTINE PUTS THE LONG PATH MODE TOGETHER
C
      COMMON / FILES / LUI, LUO, LU2, LU5, LU6, LU15, LU16, LU20, LU25,
     A LU26, LU35
      COMMON/ANOIS/ATNU,ATNY,CC,TM,RCNSE,DU,DL,SIGM,SxGU,SxGL,KJ,JK
      COMMON/MUFS/EMUF(24),F1MUF(24),F2MUF(24),ESMUF(24),ALLMUF(24),FOT
     A (24),XLUF(24),HPF(24),ANGMUF(24),MODMUF,SIGL(4),SIGU(4),DELMUF(4)
     B ,HPMUF(4),HTMUF(4),FVMUF(4),AFMUF(4),NHOPMF(4),YFOT(4),YHPF(4)
     C ,YMUF(4)
      COMMON/CON/D2R,DCL,GAMA,PI,PI2,PIO2,R2D,RZ,VOFL
      COMMON /DON /ALATD, AMIN, AMIND, BTR, BTRD, DLONG, DMP, ERTR, GCD,
     1 GCDKM, PMP, PWR, TLAT, TLATD, TLONG, TLONGD, RSN, SIGTR, RLAT,
     2 RLATD,RLONG,RLONGD,BRTD,FLUX,ULAT,ULATD,ULONG,ULONGD,SSN,D90R,
     3 D50R,D10R,D90S,D50S,D10S
      COMMON/LPATH/ GCDLNG,TXRGML(45,2),DELOPT,GMIN,YMIN,LTXRGM(2)
      COMMON/FRQ/FREA(13),FREL(29),FREQ,JMODE,ITXRCP(2)
      COMMON/LOSX/ANDVX(45,3),ADVX(45,3),AOFX(45,3),ARFX(45,3),GRLOSX(45
     A ,3),TGAINX(45,3),TLSKM(45,3),EFFlp(45),IAFTXR(3)
      COMMON/REFLX/DELFX(45,3),HPFLX(45,3),HTFLX(45,3),GDFLX(45,3),FVFLX
     A (45,3),DSKPKM(3),DELSKP(3),HPSKP(3),HTSKP(3),DMAXKM(3),FVSKP(3)
     B ,ISKP(3),IMODE(45,3),AFFLX(45,3),DELPEN(3,5),GML(45,3),FHP(45,3)
      COMMON/SIGD/DSL,ASM,DSU,AGLAT,DSLF,ASMF,DSUF,ACAV,FEAV,AFE,BFE,HNU
     A ,HTLOSS,XNUZ,XVE
      COMMON/TON/ADJ,ADS,GNOS,GOT,REL,SL,SLS,SPR,SU,SUS
     A ,XNOISE,ZNOISE,NF
      COMMON / allMODE /ABPS(20),CREL(20),FLDST(20),HN(20),HP(20),
     1PROB(20),RELY(20),RGAIN(20),SIGPOW(20),SN(20),
     2SPRO(20),TGAIN(20),TIMED(20),TLOSS(20),B(20),FSLOS(20),
     3grlos(20),adv(20),obf(20),
     CNMODE(20),TLLOW(20),TLHGH(20),EFF(20),NREL,NMMOD
      COMMON/INFORM/INFO,IHSHR,IHLNG
      CHARACTER OUTDAT*25, MR*1,ITF*1
C==========================================================
C.....LTXRGM(1) .GE. 1 AND LTXRGM(2) .GE. 1 SINCE OVER-THE-MUF ADDED
      IF(LTXRGM(1).le.0.) return
      IF(LTXRGM(2).le.0.) return
C.....AVERAGE TAKE-OFF ANGLE
      DEL = .5*D2R*(DELFX(LTXRGM(1),1) + DELFX(LTXRGM(2),ITXRCP(2)))
C.....AVERAGE VIRTUAL HEIGHT
      HPX = .5*(HPFLX(LTXRGM(1),1) + HPFLX(LTXRGM(2),ITXRCP(2)))
      RCOSD = RZ*COS(DEL)
      SPHE = RCOSD/(RZ+HPX)
      PHE  = ATAN(SPHE/SQRT(1.- SPHE*SPHE) )
      DT = .5* GDFLX(LTXRGM(1),1)/RZ
      DR = .5* GDFLX(LTXRGM(2),ITXRCP(2))/RZ
      RAY  = RZ* COS(PHE+DEL)/SPHE
C.....FREE-SPACE CONVERGENCE FACTOR
      CALL CONVH(GCD,PHE,DEL,HPX,RAY,CH,PTOT)
C.....FREE-SPACE LOSS
      FREE = 36.58 + 20.*ALOG10(.6214 *PTOT* FREQ) -CH
C.....IONOSPHERIC DISTANCE
      DI  = GCD - DT -DR
      DIKM = DI*RZ
      IF(DIKM.le.-1.) then
         DM = 0.
         AM = 0.
         AF = 0.
         DF = 0.
         GMKM=0.
      else
C.....OVER-THE-TOP DISTANCE
         CALL GETTOP(DIKM, GMKM)
         DM = GMKM/RZ
         DF = DI - DM
         DF = AMAX1(DF,0.0)
C.....LOSS PER KILOMETER
         CALL  TABS(DEL,HPX,DM,AM)
         CALL BABS(DEL,HPX,DF,AF)
      end if
C.....LOSSES
      XLM = AM*DM*RZ
      XLF = AF*DF*RZ
C  LOSS AT TRANSMITTER END.
      XLT = (ANDVX(LTXRGM(1),1) + ADVX(LTXRGM(1),1)) / 2.
C  LOSS AT RECEIVER END
      XLR = (ANDVX(LTXRGM(2),ITXRCP(2))+ADVX(LTXRGM(2),ITXRCP(2)))/2.
C.....AVERAGE GROUND LOSS
      GLOSS=.5*(GRLOSX(LTXRGM(1),1) + GRLOSX(LTXRGM(2),ITXRCP(2)) )
      FHOP = DF/(DR + DT)
      FHOP = AMAX1(FHOP,1.)
      NMMOD=1
C.....TRANSMISSION LOSS
ccc      write(luo,108) df,di,dm,gcd,dt,dr,dikm
ccc108   format('df=',6f10.6,f10.3)
ccc      write(luo,109) xlf,af,df,rz
ccc109   format('xlf=',f10.3,f10.6,f10.6,f10.3)
ccc      write(luo,111) FREE,XLT,XLM,XLF,XLR,FHOP,GLOSS,ASM
ccc111   format('free=',8f10.3)
      TLOSL = FREE + XLT + XLM + XLF + XLR + (FHOP - 1.) * GLOSS + ASM
     A        - TGAINX(LTXRGM(2),ITXRCP(2)) - TGAINX(LTXRGM(1),1)
ccc      write(luo,'(''tlosl='',f10.3)') tlosl
      GRLOS (1) = GLOSS
      HN(1) = 0.5 * GCD / (DR + DT)
C.....NUMBER OF HOPS
      HN(1) = AMAX1(1.0,HN(1) )
C.....VIRTUAL HEIGHT
      HP(1)   = HPX
C.....ANTENNA GAIN
      RGAIN(1)= TGAINX(LTXRGM(2),ITXRCP(2))
      TGAIN(1)= TGAINX(LTXRGM(1),1)
      EFF(1) = EFFlp(ltxrgm(2))
C.....TIME DELAY
      TIMED(1) = PTOT/VOFL
      TLOSS(1) =  TLOSL
C.....TRANSMISSION ANGLE
      B(1)     =  DELFX(LTXRGM(1),1)
C.....RECEPTION ANGLE
      B(2)     =  DELFX(LTXRGM(2),ITXRCP(2))
C.....MODE TYPE
      NMODE(1) = IMODE(LTXRGM(1),1)
      NMODE(2) = IMODE(LTXRGM(2),ITXRCP(2))
      FSLOS(1) =  FREE
      ADV(1)   = (ADVX(LTXRGM(1),1) + ADVX(LTXRGM(2),ITXRCP(2)))*.5
      ABPS(1)  =(ANDVX(LTXRGM(1),1) +ANDVX(LTXRGM(2),ITXRCP(2)))*.5
      OBF(1)   =(AOFX(LTXRGM(1),1) + AOFX(LTXRGM(2),ITXRCP(2)))*.5
      SIGPOW(1)= PWRDB(FREQ) - TLOSL
C.....FIELD STRENGTH
      FLDST(1) = 107.2 + PWRDB(FREQ) + 20.*ALOG10(FREQ)-TLOSL-RGAIN(1)
C.....SNR
C------------    CHANGED 9/24/91  (LONG PATH RCVR EFF CORRECTION)  FJR
C------------            SN(1) = SIGPOW(1) - RCNSE
      SN(1) = SIGPOW(1) - RCNSE - EFF(1)
      ITRY = 1
      IS = NMODE(1)
  200 DUMMY = YMUF(IS)
      P = PRBMUF(FREQ,DUMMY,DUMMY,IS)
      ZLMUF = -10.*ALOG10(P)
      DUMMY = YFOT(IS)
      P = PRBMUF(FREQ,DUMMY,DUMMY,IS)
      ZLFOT = -10.*ALOG10(P)
      DUMMY = YHPF(IS)
      P = PRBMUF(FREQ,DUMMY,DUMMY,IS)
       ZLHPF = -10.*ALOG10(P)
      CPR = FVMUF(IS)/YMUF(IS)
      DSLF = ( ZLFOT - ZLMUF ) / CPR
      DSUF = ( ZLMUF - ZLHPF ) / CPR
      IF( ITRY -1 ) 250,250,260
  250 IF(IS - NMODE(2) ) 255,265,255
  255 ITRY = 2
      IS = NMODE(2)
      DSLFF = DSLF
      DSUFF = DSUF
      GO TO 200
  260 DSUF = .5 * (DSUF + DSUFF)
      DSLF = .5 * (DSLF + DSLFF)
  265 TLLOW(1) =DSL + HN(1) * DSLF
      TLHGH(1) =DSU + HN(1) * DSUF
C.....LOWER DECILE
      TLLOW(1) = AMIN1( TLLOW(1), 25.)
C.....UPPER DECILE
      TLHGH(1) = AMIN1( TLHGH(1), 25.)
C--------------------------------
      IF(IAND(INFO,128).GT.0)THEN
        ITF=CHAR(12)
        DO 280 JJ=1,2
        WRITE(99,'(A1,20X,20hCONTROL AREA NUMBER ,I2,3X,11HMOST RELIAB,
     1  3HLE ,I3,/,44H IDX    ABSORP   DEV LOS    OBSCUR    GR LOS,4X,
     2  31HA.GAIN   GN-LOS   F HOP  TO ANG,/)')ITF,ITXRCP(JJ),LTXRGM(JJ)
        K=ITXRCP(JJ)
        DO 275 IA=1,IAFTXR(K)
        IF((GML(IA,K).EQ.-999..AND.FHP(IA,K).EQ.999.).OR.
     1  (ANDVX(IA,K).EQ.1000..AND.ADVX(IA,K).EQ.1000.))THEN
          OUTDAT=' '
        ELSE
         WRITE(OUTDAT,'(F9.2,F8.4,F8.3)')GML(IA,K),FHP(IA,K),DELFX(IA,K)
        ENDIF
        MR=' '
        IF(IA.EQ.LTXRGM(JJ))THEN
          WRITE(OUTDAT(10:10),'(1H*)')
          WRITE(OUTDAT(18:18),'(1H*)')
          MR='*'
        ENDIF
        WRITE(99,'(I4,A1,5F10.2,A25)')IA,MR,ANDVX(IA,K),ADVX(IA,K),
     1  AOFX(IA,K),GRLOSX(IA,K),TGAINX(IA,K),OUTDAT
  275   CONTINUE
  280   CONTINUE
        NHOPS=HN(1)+.01
        WRITE(99,'(/,/,  14H  NUMBER HOPS ,I3,22H  MOST RELIABLE MODES:,
     1  8H   XMTR ,I3,8H   RCVR ,I3,/,11H  F.S.LOSS ,F8.2,3X,8H F-DAYS ,
     2  6H XMTR ,F5.2,6H RCVR ,F5.2)')NHOPS,LTXRGM(1),LTXRGM(2),FREE,
     3  PROB(1), PROB(2)
      ENDIF
C.....F.DAYS
      PROB(1) = AMIN1( PROB(1), PROB(2))
      RETURN
      END
C--------------------------------
